package com.hopu.oa.dao.UserManage;

import com.hopu.oa.entity.user.AoaDept;
import com.hopu.oa.entity.user.AoaPosition;
import com.hopu.oa.entity.user.AoaUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface deptManageDao {

    @Select("select * from aoa_dept")
    List<AoaDept> findAllDepts();

    /**
     * 分页操作和页面操作
     */
    List<AoaDept> findAllDept(String deptName, @Param("index") int index, @Param("size") int size);

    @Select("select * from aoa_dept where dept_id=#{deptId}")
    AoaDept findDeptById(int id);

    @Select("select * from aoa_dept")
    List<AoaDept> findDept();

    @Select("select * from aoa_dept where dept_name=#{deptName}")
    AoaDept findDeptByDeptName(String deptName);


    @Select("select * from aoa_dept where dept_name=#{deptName}")
    int findDeptByDeptNameId(String deptName);

    @Insert("insert into aoa_dept (dept_name,dept_tel,dept_fax,email,dept_addr,start_time,end_time) values(#{deptName},#{deptTel},#{deptFax},#{email},#{deptAddr},#{startTime},#{endTime})")
    int insertDept(String deptName, String deptTel, String deptFax, String email, String deptAddr, String startTime, String endTime);

    @Update("update aoa_dept set dept_name=#{deptName},dept_tel=#{deptTel},dept_fax=#{deptFax},email=#{email},dept_addr=#{deptAddr},end_time=#{endTime} where dept_id=#{deptId}")
    int updateDept(String deptName, String deptTel, String deptFax, String email, String deptAddr, String endTime, int deptId);

    @Select("select * from aoa_user where dept_id=#{deptId}")
    List<AoaUser> findAllUserByDeptId(int deptId);

    @Delete("delete from aoa_dept where dept_id=#{deptId}")
    int deleteDept(int deptId);


    /**
     * 人事调动操作
     */
    @Select("select * from aoa_dept")
    List<AoaDept> selectDepts();


    List<AoaUser> selectUserBydeptId(int deptid);


    AoaUser selectRelaName(int deptid);


    @Select("select * from aoa_dept where dept_id =#{deptid}")
    AoaDept selectDeptById(int deptid);

    @Select("select * from aoa_position where deptid=#{deptid}")
    List<AoaPosition> selectPositionById(int deptid);

    @Select("select * from aoa_dept")
    List<AoaDept> selectdeptAll();

    @Update("update  aoa_user set position_id=#{positionid},dept_id=#{deptid} where user_id=#{userid}")
    int updatePositionById(int userid, int positionid, int deptid);

    @Update("update aoa_dept set deptmanager=#{juserid} where dept_id=#{deptid}")
    int updateDeptmanager(int juserid, int deptid);


}
